package com.example.tests;

import org.junit.*;
import static org.junit.Assert.*;

import com.example.pages.UserPage;

public class CreateNewUserTest extends TestBase {

	@Test
	public void createNewUser() {
		UserPage userPage = goToMainPage()
		.loginWithValidCredentials("admin", "admin")
		.gotoUserManagementConsole();
		
		//int oldSize = userPage.getUserCount();
		SortedListOf<User> oldUserList = userPage.getUsers();
		
		User user = new User()
			.withName("user1").withEmail("user1@test.com").withPassword("test");
		if(oldUserList.contains(user)){
			userPage.deleteUser(user);
			oldUserList = userPage.getUsers();
		}
		
		userPage.createUser(user);
		
		//int newSize = userPage.getUserCount();
		SortedListOf<User> newUserList = userPage.getUsers();
		// compare new list and old list 
		
		//assertEquals(newSize, oldSize + 1);
		assertEquals(newUserList, oldUserList.withAdded(user));
		
	}
}
